use std::cell::RefCell;
use std::rc::Rc;

#[derive(Debug, PartialEq, Eq)]
pub struct TreeNode {
    pub val: i32,
    pub left: Option<Rc<RefCell<TreeNode>>>,
    pub right: Option<Rc<RefCell<TreeNode>>>,
}

impl TreeNode {
    #[inline]
    pub fn new(val: i32) -> Self {
        TreeNode {
            val,
            left: None,
            right: None,
        }
    }
}

struct Solution;

impl Solution {
    pub fn inorder_traversal(root: Option<Rc<RefCell<TreeNode>>>) -> Vec<i32> {
        let mut result = vec![];
        fn traversal(result: &mut Vec<i32>, root: &Option<Rc<RefCell<TreeNode>>>) {
            if let Some(inner) = root {
                let x = inner.borrow();
                traversal(result, &x.left);
                result.push(x.val);
                traversal(result, &x.right);
            }
        }
        traversal(&mut result, &root);
        result
    }
}